
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>自定义关键字 · sosotest</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../A0005_pythonmode/" />
    
    
    <link rel="prev" href="A02_buildin.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    sosotest平台介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../A0000_quickstart/A00_install.html">
            
                <a href="../A0000_quickstart/A00_install.html">
            
                    
                    安装部署sosotest服务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../A0000_quickstart/">
            
                <a href="../A0000_quickstart/">
            
                    
                    使用配置入门
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../A0000_quickstart/A01_system_config.html">
            
                <a href="../A0000_quickstart/A01_system_config.html">
            
                    
                    管理员配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../A0000_quickstart/A02_user_config.html">
            
                <a href="../A0000_quickstart/A02_user_config.html">
            
                    
                    用户配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../A0000_quickstart/A03_interface.html">
            
                <a href="../A0000_quickstart/A03_interface.html">
            
                    
                    用例编写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../A0000_quickstart/A04_task.html">
            
                <a href="../A0000_quickstart/A04_task.html">
            
                    
                    任务与任务集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../A0000_quickstart/A05_cicd.html">
            
                <a href="../A0000_quickstart/A05_cicd.html">
            
                    
                    持续集成
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../A0001_admin/">
            
                <a href="../A0001_admin/">
            
                    
                    后台管理部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../A0001_admin/A01_login.html">
            
                <a href="../A0001_admin/A01_login.html">
            
                    
                    管理员登录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../A0001_admin/A02_user_group_manage.html">
            
                <a href="../A0001_admin/A02_user_group_manage.html">
            
                    
                    用户小组管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../A0001_admin/A03_permission.html">
            
                <a href="../A0001_admin/A03_permission.html">
            
                    
                    权限管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../A0001_admin/A04_admin.html">
            
                <a href="../A0001_admin/A04_admin.html">
            
                    
                    管理员管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../A0001_admin/A05_config.html">
            
                <a href="../A0001_admin/A05_config.html">
            
                    
                    平台配置管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../A0002_user/">
            
                <a href="../A0002_user/">
            
                    
                    用户使用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../A0002_user/A01_config.html">
            
                <a href="../A0002_user/A01_config.html">
            
                    
                    配置管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../A0002_user/A02_http.html">
            
                <a href="../A0002_user/A02_http.html">
            
                    
                    HTTP接口测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../A0002_user/A03_dubbo.html">
            
                <a href="../A0002_user/A03_dubbo.html">
            
                    
                    DUBBO接口测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../A0002_user/A04_globalvar.html">
            
                <a href="../A0002_user/A04_globalvar.html">
            
                    
                    全局变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../A0002_user/A05_text.html">
            
                <a href="../A0002_user/A05_text.html">
            
                    
                    组合文本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../A0003_mock/">
            
                <a href="../A0003_mock/">
            
                    
                    MOCK服务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../A0003_mock/A02_createmock.html">
            
                <a href="../A0003_mock/A02_createmock.html">
            
                    
                    新建mock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../A0003_mock/A03_requestmock.html">
            
                <a href="../A0003_mock/A03_requestmock.html">
            
                    
                    请求mock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../A0003_mock/A04_recodermock.html">
            
                <a href="../A0003_mock/A04_recodermock.html">
            
                    
                    mock录制
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="./">
            
                <a href="./">
            
                    
                    关键字模式介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="A01_use.html">
            
                <a href="A01_use.html">
            
                    
                    使用关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="A02_buildin.html">
            
                <a href="A02_buildin.html">
            
                    
                    内置关键字介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.3" data-path="A03_selfdefine.html">
            
                <a href="A03_selfdefine.html">
            
                    
                    自定义关键字
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../A0005_pythonmode/">
            
                <a href="../A0005_pythonmode/">
            
                    
                    python模式介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../A0005_pythonmode/A01_use.html">
            
                <a href="../A0005_pythonmode/A01_use.html">
            
                    
                    使用python模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../A0005_pythonmode/A02_buildin.html">
            
                <a href="../A0005_pythonmode/A02_buildin.html">
            
                    
                    内置python函数介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../A0005_pythonmode/A03_selfdefine.html">
            
                <a href="../A0005_pythonmode/A03_selfdefine.html">
            
                    
                    自定义python
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../A0005_pythonmode/A04_ddt.html">
            
                <a href="../A0005_pythonmode/A04_ddt.html">
            
                    
                    数据驱动DDT
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../A0010_context/">
            
                <a href="../A0010_context/">
            
                    
                    context上下文对象
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../A0010_context/A01_vars.html">
            
                <a href="../A0010_context/A01_vars.html">
            
                    
                    常用变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../A0010_context/A02_functions.html">
            
                <a href="../A0010_context/A02_functions.html">
            
                    
                    常用函数
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../A0009_data/">
            
                <a href="../A0009_data/">
            
                    
                    数据操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../A0009_data/A01_mysqldb.html">
            
                <a href="../A0009_data/A01_mysqldb.html">
            
                    
                    mysql数据库操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../A0009_data/A02_redis.html">
            
                <a href="../A0009_data/A02_redis.html">
            
                    
                    redis缓存操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../A0009_data/A03_mongo.html">
            
                <a href="../A0009_data/A03_mongo.html">
            
                    
                    mongo数据库操作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../A0006_ci/">
            
                <a href="../A0006_ci/">
            
                    
                    持续集成
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../A0006_ci/A01_invoke.html">
            
                <a href="../A0006_ci/A01_invoke.html">
            
                    
                    invoke接口介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../A0006_ci/A02_cishell.html">
            
                <a href="../A0006_ci/A02_cishell.html">
            
                    
                    CI shell 脚本说明
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../A0007_assert/">
            
                <a href="../A0007_assert/">
            
                    
                    断言处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../A0007_assert/A01_contains.html">
            
                <a href="../A0007_assert/A01_contains.html">
            
                    
                    包含断言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../A0007_assert/A02_recurjson.html">
            
                <a href="../A0007_assert/A02_recurjson.html">
            
                    
                    递归JSON断言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../A0007_assert/A03_conditionbool.html">
            
                <a href="../A0007_assert/A03_conditionbool.html">
            
                    
                    条件断言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../A0007_assert/A04_assertstruct.html">
            
                <a href="../A0007_assert/A04_assertstruct.html">
            
                    
                    结构断言
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../A0008_errors/">
            
                <a href="../A0008_errors/">
            
                    
                    常见错误原因
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../A0008_errors/A03_other.html">
            
                <a href="../A0008_errors/A03_other.html">
            
                    
                    莫名其妙的错误
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >自定义关键字</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;">&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;</h1>
<p>&#x6309;&#x7167;&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;&#x89C4;&#x8303;&#xFF0C;&#x7528;&#x6237;&#x53EF;&#x4EE5;&#x7F16;&#x5199;&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x7136;&#x540E;&#x7528;&#x4E8E;&#x7528;&#x4F8B;&#x4E2D;&#x3002;<br>
&#x8FDB;&#x5165;&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;&#x7684;&#x83DC;&#x5355;&#x8DEF;&#x5F84;&#x662F; <code>&#x6570;&#x636E;&#x670D;&#x52A1;-&gt;KEYWORD/PYTHON&#x6A21;&#x5F0F;-&gt;&#x65B0;&#x589E;&#x5173;&#x952E;&#x5B57;</code> <br></p>
<blockquote>
<p>&#x6CE8;&#xFF1A;&#x5E73;&#x53F0;&#x4E0D;&#x5141;&#x8BB8;&#x7528;&#x6237;&#x5199;&#x4EE3;&#x7801;&#x65F6;&#x4F7F;&#x7528;import&#x5F15;&#x5165;&#x5305;&#xFF0C;&#x6240;&#x6709;&#x6709;import&#x5F15;&#x7528;&#x5305;&#x7684;&#x9700;&#x6C42;&#x9700;&#x8981;&#x8054;&#x7CFB;&#x7BA1;&#x7406;&#x5458;&#x6DFB;&#x52A0;&#x3002;</p>
</blockquote>
<h2 id="&#x9ED8;&#x8BA4;&#x5F15;&#x5165;&#x7684;&#x5305;">&#x9ED8;&#x8BA4;&#x5F15;&#x5165;&#x7684;&#x5305;</h2>
<p>&#x7F16;&#x5199;&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;&#x65F6;&#xFF0C;&#x9ED8;&#x8BA4;&#x5F15;&#x5165;&#x4E86;&#x5982;&#x4E0B;&#x5305;&#xFF1A;<br></p>
<pre><code class="lang-python"><span class="hljs-comment">#&#x5B57;&#x7B26;&#x4E32;&#x5904;&#x7406;&#x76F8;&#x5173;&#x7684;&#x5E93;</span>
<span class="hljs-keyword">import</span> json,re,jsonpath,hashlib,ast
<span class="hljs-keyword">from</span> urllib <span class="hljs-keyword">import</span> parse
<span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> reduce
<span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup
<span class="hljs-comment">#&#x65F6;&#x95F4;&#x5904;&#x7406;&#x76F8;&#x5173;&#x7684;&#x5E93;</span>
<span class="hljs-keyword">import</span> datetime,time,calendar
<span class="hljs-comment">#&#x6570;&#x5B66;&#x5904;&#x7406;</span>
<span class="hljs-keyword">import</span> math,cmath,decimal
<span class="hljs-comment">#web&#x8BF7;&#x6C42;&#x76F8;&#x5173;</span>
<span class="hljs-keyword">import</span> requests
<span class="hljs-comment">#&#x5F02;&#x5E38;&#x5904;&#x7406;</span>
<span class="hljs-keyword">import</span> traceback
<span class="hljs-comment">#&#x6570;&#x636E;&#x5E93;&#x76F8;&#x5173;</span>
<span class="hljs-keyword">import</span> pymysql,redis
<span class="hljs-keyword">from</span> kafka <span class="hljs-keyword">import</span> KafkaProducer
<span class="hljs-keyword">from</span> kafka <span class="hljs-keyword">import</span> KafkaConsumer
<span class="hljs-keyword">from</span> kafka.errors <span class="hljs-keyword">import</span> KafkaError
</code></pre>
<h2 id="&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;&#x89C4;&#x8303;">&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;&#x89C4;&#x8303;</h2>
<p>&#x7F16;&#x5199;&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x9700;&#x8981;&#x9075;&#x5FAA;&#x5982;&#x4E0B;&#x89C4;&#x8303;&#xFF1A;<br></p>
<pre><code class="lang-python"><span class="hljs-meta">@keyword()</span>
<span class="hljs-meta">@catch_exception</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">DEMO_SELF_KEYWORD</span><span class="hljs-params">(value,context,strTobeProcessed = <span class="hljs-string">&quot;&quot;</span>)</span>:</span>
    <span class="hljs-comment">#&#x4F60;&#x8C03;&#x7528;&#x5173;&#x952E;&#x5B57;&#x65F6;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x5217;&#x8868;&#xFF0C;</span>
    <span class="hljs-comment">#&#x4F8B;&#x5982;DEMO_SELF_KEYWORD(a,b,c)&#xFF0C;&#x5904;&#x7406;&#x540E;&#x7684;paramList&#x5C31;&#x662F;&#x5217;&#x8868;[&apos;a&apos;,&apos;b&apos;,&apos;c&apos;]</span>
    paramList = getParamList(strTobeProcessed, context)
    <span class="hljs-comment">#&#x4F8B;&#x5982;DEMO_SELF_KEYWORD(p1,p2,k1 = v1,k2 = v2),&#x5904;&#x7406;&#x540E;&#x7684;paramList&#x5C31;&#x662F;&#x5217;&#x8868;[&apos;p1&apos;,&apos;p2&apos;],paramDict&#x5C31;&#x662F;&#x5B57;&#x5178;{&apos;k1&apos;:&apos;v1&apos;,&apos;k2&apos;:&apos;v2&apos;}</span>
    paramList,paramDict = getParamListAndKWParam(strTobeProcessed, context)

    <span class="hljs-comment">#&#x4F60;&#x8C03;&#x7528;&#x7684;&#x5173;&#x952E;&#x5B57;&#x5904;&#x7406;&#x540E;&#x7684;&#x503C;&#xFF0C;&#x672A;&#x5206;&#x5272;</span>
    <span class="hljs-comment">#&#x4F8B;&#x5982;DEMO_SELF_KEYWORD($VAR[a],b,c)&#xFF0C;&#x5047;&#x8BBE;&#x53D8;&#x91CF;a=1&#xFF0C;&#x5904;&#x7406;&#x540E;&#x7684;strTobeProcessed&#x5C31;&#x662F;&#x5B57;&#x7B26;&#x4E32;1,b,c</span>
    strTobeProcessed = core.processor.KP.KP.getProcessedValue(strTobeProcessed, context)

    <span class="hljs-comment">#&#x4F60;&#x7684;&#x4EE3;&#x7801;&#x5728;&#x8FD9;&#x91CC;&#x9762;&#x5199;&#x2193;</span>
    <span class="hljs-comment">#return &#x662F;&#x4F60;&#x60F3;&#x8981;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x5FC5;&#x987B;&#x6709;&#xFF0C;&#x6309;&#x7167;&#x81EA;&#x5DF1;&#x7684;&#x8981;&#x6C42;&#x5199;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x662F;str</span>
    <span class="hljs-keyword">return</span> int(paramList[<span class="hljs-number">0</span>])+int(paramList[<span class="hljs-number">1</span>])+int(paramList[<span class="hljs-number">2</span>])
</code></pre>
<p>&#x8BF4;&#x660E;&#xFF1A;</p>
<blockquote>
<p>1&#x3001;&#x5F00;&#x5934;&#x5FC5;&#x987B;&#x4F7F;&#x7528;&#x88C5;&#x9970;&#x5668;@keyword @catch_exception&#x3002;<br>
2&#x3001;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x5FC5;&#x987B;&#x7B26;&#x5408;&#x89C4;&#x8303;&#x3002;def DEMO_SELF_KEYWORD(value,context,strTobeProcessed = &quot;&quot;):&#x3002;<br>
3&#x3001;&#x83B7;&#x53D6;&#x53C2;&#x6570;&#x5217;&#x8868;&#x65B9;&#x5F0F;&#xFF1A;paramList = getParamList(strTobeProcessed, context)<br>
4&#x3001;&#x83B7;&#x53D6;&#x53C2;&#x6570;&#x5217;&#x8868;&#x7684;&#x5B57;&#x5178;&#x53C2;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#xFF1A;paramList,paramDict = getParamListAndKWParam(strTobeProcessed, context)<br>
5&#x3001;&#x5904;&#x7406;&#x6240;&#x6709;&#x5165;&#x53C2;&#xFF0C;&#x5373;&#x6574;&#x4E2A;&#x53C2;&#x6570;&#x53EA;&#x6709;1&#x4E2A;&#x53C2;&#x6570;&#x65F6;&#xFF1A;strTobeProcessed = core.processor.KP.KP.getProcessedValue(strTobeProcessed, context)<br>
6&#x3001;return &#x5FC5;&#x987B;&#x6709;&#x3002;<br>
7&#x3001;&#x5173;&#x952E;&#x5B57;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;value,context,strTobeProcessed = &quot;&quot;&#x7684;&#x8BF4;&#x660E;&#xFF1A;<br>
    value&#xFF1A;&#x65E0;&#x9700;&#x5173;&#x5FC3;&#xFF0C;&#x88C5;&#x9970;&#x5668;keyword&#x4F1A;&#x5904;&#x7406;&#x3002;
    context&#xFF1A;&#x4E0A;&#x4E0B;&#x6587;&#x5BF9;&#x8C61;&#xFF0C;&#x5BF9;&#x8C61;&#x4E2D;&#x4F1A;&#x6709;&#x5404;&#x79CD;&#x5C5E;&#x6027;&#x548C;&#x51FD;&#x6570;&#xFF0C;&#x8BE6;&#x89C1;context&#x5BF9;&#x8C61;&#x8BF4;&#x660E;&#x3002;
    strTobeProcessed&#xFF1A;&#x8981;&#x5904;&#x7406;&#x7684;&#x5B50;&#x4E32;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x5173;&#x952E;&#x5B57;&#x8C03;&#x7528;&#x65F6;&#x7684;&#x53C2;&#x6570;&#x90E8;&#x5206;&#x3002;  </p>
</blockquote>
<h2 id="&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;&#x793A;&#x4F8B;">&#x81EA;&#x5B9A;&#x4E49;&#x5173;&#x952E;&#x5B57;&#x793A;&#x4F8B;</h2>
<h2 id="&#x767B;&#x5F55;login">&#x767B;&#x5F55;LOGIN</h2>
<p>&#x5047;&#x8BBE;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;HTTP&#x63A5;&#x53E3;&#x7684;&#x767B;&#x5F55;&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x4F20;&#x5165;&#x7528;&#x6237;&#x540D;&#x5BC6;&#x7801;&#xFF0C;&#x8BF7;&#x6C42;&#x767B;&#x5F55;&#x63A5;&#x53E3;/user/login&#xFF0C;&#x7136;&#x540E;&#x8FDB;&#x884C;&#x767B;&#x5F55;&#x3002;<br>
&#x8C03;&#x7528;&#x793A;&#x4F8B;&#xFF1A;LOGIN(zhangsan,123456);<br>
&#x77E5;&#x8BC6;&#x70B9;&#xFF1A;<br>
1&#x3001;&#x751F;&#x6210;&#x53C2;&#x6570;&#x5217;&#x8868;list&#x3002;<br>
2&#x3001;&#x4F7F;&#x7528;&#x4E0A;&#x4E0B;&#x6587;&#x7684;session&#x3002;<br>
3&#x3001;&#x4F7F;&#x7528;&#x4E0A;&#x4E0B;&#x6587;&#x7684;datalist&#x4F20;&#x9012;&#x767B;&#x5F55;&#x72B6;&#x6001;&#xFF0C;&#x5728;&#x4E00;&#x4E2A;&#x4F1A;&#x8BDD;&#x4E2D;&#x5B9E;&#x73B0;&#x4E00;&#x6B21;&#x767B;&#x5F55;&#x540E;&#x7EED;&#x514D;&#x767B;&#x9646;&#x64CD;&#x4F5C;&#x3002;<br></p>
<pre><code class="lang-python"><span class="hljs-meta">@keyword()</span>
<span class="hljs-meta">@catch_exception</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">LOGIN</span><span class="hljs-params">(value,context,strTobeProcessed = <span class="hljs-string">&quot;&quot;</span>)</span>:</span>
    <span class="hljs-comment">#LOGIN(username,password),&#x6267;&#x884C;&#x4E0B;&#x9762;&#x8BED;&#x53E5;&#x540E;&#xFF0C;paramList = [&quot;username&quot;,&quot;password&quot;]</span>
    paramList = getParamList(strTobeProcessed, context)
    retmsg = <span class="hljs-string">&quot;&quot;</span> <span class="hljs-comment"># &#x8981;&#x8FD4;&#x56DE;&#x7684;&#x4FE1;&#x606F;</span>
    <span class="hljs-keyword">if</span> len(paramList) != <span class="hljs-number">2</span>:
        <span class="hljs-comment"># &#x53C2;&#x6570;&#x957F;&#x5EA6;&#x4E0D;&#x7B26;&#x5408;&#x8981;&#x6C42;&#xFF0C;&#x62A5;&#x9519;&#x3002;</span>
        retmsg = <span class="hljs-string">&quot;&lt;ERROR: &#x53C2;&#x6570;&#x9519;&#x8BEF;&#xFF0C;&#x957F;&#x5EA6;&#x5FC5;&#x987B;&#x662F;2&gt;&quot;</span>
        context.setERROR(retmsg)
        <span class="hljs-keyword">return</span> retmsg

    <span class="hljs-comment">#&#x53C2;&#x6570;&#x6821;&#x9A8C;&#x901A;&#x8FC7;&#x540E;&#xFF0C;&#x7ED9;username&#x548C;password&#x8D4B;&#x503C;&#x3002;</span>
    username = paramList[<span class="hljs-number">0</span>]
    password = paramList[<span class="hljs-number">1</span>]
    host = context.host

    <span class="hljs-comment"># &#x8FDB;&#x884C;&#x514D;&#x767B;&#x9646;&#x5224;&#x65AD;&#xFF0C;&#x5F53;&#x6267;&#x884C;&#x4EFB;&#x52A1;&#x6216;&#x8005;&#x4E1A;&#x52A1;&#x6D41;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x4E0D;&#x91CD;&#x590D;&#x767B;&#x5F55;&#x3002;</span>
    <span class="hljs-comment"># context.context_data_list &#x662F;&#x4E0A;&#x4E0B;&#x6587;&#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x4E0A;&#x4E0B;&#x6587;&#x4F20;&#x9012;&#x6570;&#x636E;&#x5217;&#x8868;&#x3002;&#x53EF;&#x4EE5;&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#x6570;&#x636E;&#x3002;</span>
    isContinue = <span class="hljs-keyword">False</span> <span class="hljs-comment"># &#x662F;&#x5426;&#x7EE7;&#x7EED;&#x767B;&#x5F55;&#xFF0C;&#x5982;&#x679C;&#x7528;&#x6237;&#x540D;&#x5BC6;&#x7801;&#x4E3B;&#x673A;&#x90FD;&#x4E00;&#x81F4;&#xFF0C;&#x5C31;&#x7EE7;&#x7EED;&#xFF0C;&#x4E0D;&#x91CD;&#x65B0;&#x767B;&#x5F55;&#x3002;</span>
    <span class="hljs-keyword">if</span> len(context.context_data_list) == <span class="hljs-number">3</span>:
        <span class="hljs-keyword">if</span> username != context.context_data_list[<span class="hljs-number">0</span>].strip() <span class="hljs-keyword">or</span> password != context.context_data_list[<span class="hljs-number">1</span>].strip() <span class="hljs-keyword">or</span> host != context.context_data_list[<span class="hljs-number">1</span>].strip():
            isContinue = <span class="hljs-keyword">True</span>
    <span class="hljs-keyword">else</span>:
        isContinue = <span class="hljs-keyword">True</span>

    <span class="hljs-keyword">if</span> isContinue:
        <span class="hljs-comment"># &#x5982;&#x679C;&#x7EE7;&#x7EED;&#xFF0C;&#x91CD;&#x7F6E;&#x4E0A;&#x4E0B;&#x6587;&#x6570;&#x636E;&#x5217;&#x8868;&#x3002;</span>
        context.context_data_list = []
    <span class="hljs-keyword">else</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x3010;&#x5DF2;&#x767B;&#x5F55;&#x3011;&#x7528;&#x6237;%s-Host[%s]&#xFF0C;&#x4E0D;&#x518D;&#x6B21;&#x6267;&#x884C;&#x767B;&#x5F55;&#xFF01;&quot;</span> % (username,host)

    <span class="hljs-comment"># &#x4F7F;&#x7528;&#x4E0A;&#x4E0B;&#x6587;&#x7684;session&#x8FDB;&#x884C;&#x767B;&#x5F55;&#x64CD;&#x4F5C;&#x3002;</span>
    context.current_session = requests.session() <span class="hljs-comment"># &#x91CD;&#x7F6E;session&#xFF0C;&#x7136;&#x540E;&#x4F7F;&#x7528;&#x65B0;session&#x91CD;&#x65B0;&#x767B;&#x5F55;&#x3002;</span>
    resp_obj = context.current_session.post(host+<span class="hljs-string">&quot;/user/login&quot;</span>,data=<span class="hljs-string">&quot;username=%s&amp;password=%s&quot;</span> % (username,password))
    <span class="hljs-keyword">if</span> <span class="hljs-string">&quot;success&quot;</span> <span class="hljs-keyword">in</span> resp_obj.text:
        <span class="hljs-comment"># &#x767B;&#x5F55;&#x6210;&#x529F;&#x540E;&#xFF0C;&#x6DFB;&#x52A0;&#x6570;&#x636E;&#x5230; &#x4E0A;&#x4E0B;&#x6587;&#x6570;&#x636E;&#x5217;&#x8868; context.context_data_list</span>
        context.context_data_list.append(username)
        context.context_data_list.append(password)
        context.context_data_list.append(host)
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x767B;&#x5F55;&#x6210;&#x529F;&#xFF01;&quot;</span>
    <span class="hljs-keyword">else</span>:
        <span class="hljs-comment"># &#x767B;&#x5F55;&#x5931;&#x8D25;&#xFF0C;&#x91CD;&#x7F6E;session&#x3002;</span>
        context.current_session = requests.session() <span class="hljs-comment"># &#x91CD;&#x7F6E;session&#xFF0C;&#x7136;&#x540E;&#x4F7F;&#x7528;&#x65B0;session&#x91CD;&#x65B0;&#x767B;&#x5F55;&#x3002;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x767B;&#x5F55;&#x5931;&#x8D25;&#xFF01;&quot;</span>
</code></pre>
<h2 id="&#x4F7F;&#x7528;md5&#x751F;&#x6210;&#x7B7E;&#x540D;-sign">&#x4F7F;&#x7528;MD5&#x751F;&#x6210;&#x7B7E;&#x540D; SIGN</h2>
<p>&#x5047;&#x8BBE;&#x540E;&#x7AEF;&#x9700;&#x8981;&#x4F7F;&#x7528;md5&#x5BF9;&#x5BC6;&#x94A5;&#x548C;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x6233;&#x8FDB;&#x884C;&#x52A0;&#x5BC6;&#x7684;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x9A8C;&#x7B7E;&#x3002;<br>
&#x8C03;&#x7528;&#x793A;&#x4F8B;&#xFF1A;signmd5str = SIGN(secretkey,timestamp);<br></p>
<pre><code class="lang-python"><span class="hljs-meta">@keyword()</span>
<span class="hljs-meta">@catch_exception</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">SIGN</span><span class="hljs-params">(value,context,strTobeProcessed = <span class="hljs-string">&quot;&quot;</span>)</span>:</span>
    <span class="hljs-comment"># &#x5C06;&#x53C2;&#x6570;&#x5904;&#x7406;&#x4E00;&#x4E0B;&#xFF0C;&#x751F;&#x6210;&#x6700;&#x7EC8;&#x5B57;&#x7B26;&#x4E32;</span>
    paramList = getParamList(strTobeProcessed, context)
    retmsg = <span class="hljs-string">&quot;&quot;</span> <span class="hljs-comment"># &#x8981;&#x8FD4;&#x56DE;&#x7684;&#x4FE1;&#x606F;</span>
    <span class="hljs-keyword">if</span> len(paramList) != <span class="hljs-number">2</span>:
        <span class="hljs-comment"># &#x53C2;&#x6570;&#x957F;&#x5EA6;&#x4E0D;&#x7B26;&#x5408;&#x8981;&#x6C42;&#xFF0C;&#x62A5;&#x9519;&#x3002;</span>
        retmsg = <span class="hljs-string">&quot;&lt;ERROR: &#x53C2;&#x6570;&#x9519;&#x8BEF;&#xFF0C;&#x957F;&#x5EA6;&#x5FC5;&#x987B;&#x662F;2&gt;&quot;</span>
        context.setERROR(retmsg)
        <span class="hljs-keyword">return</span> retmsg
    <span class="hljs-comment">#&#x53C2;&#x6570;&#x6821;&#x9A8C;&#x901A;&#x8FC7;&#x540E;&#xFF0C;&#x7ED9;username&#x548C;password&#x8D4B;&#x503C;&#x3002;</span>
    secretKey = paramList[<span class="hljs-number">0</span>]
    timestamp = paramList[<span class="hljs-number">1</span>]
    <span class="hljs-comment">#&#x5BF9;key&#x8FDB;&#x884C;&#x6392;&#x5E8F;</span>
    md = hashlib.md5()  <span class="hljs-comment"># &#x521B;&#x5EFA;md5&#x5BF9;&#x8C61;</span>
    md.update(( timestamp + secretKey).encode(encoding=<span class="hljs-string">&apos;utf-8&apos;</span>))
    signature=md.hexdigest()
    <span class="hljs-comment">#&#x4F60;&#x7684;&#x4EE3;&#x7801;&#x5728;&#x8FD9;&#x91CC;&#x9762;&#x5199;&#x2193;</span>
    <span class="hljs-comment">#return &#x662F;&#x4F60;&#x60F3;&#x8981;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x5FC5;&#x987B;&#x6709;&#xFF0C;&#x6309;&#x7167;&#x81EA;&#x5DF1;&#x7684;&#x8981;&#x6C42;&#x5199;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x662F;str</span>
    <span class="hljs-keyword">return</span> signature
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="A02_buildin.html" class="navigation navigation-prev " aria-label="Previous page: 内置关键字介绍">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../A0005_pythonmode/" class="navigation navigation-next " aria-label="Next page: python模式介绍">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"自定义关键字","level":"1.7.3","depth":2,"next":{"title":"python模式介绍","level":"1.8","depth":1,"path":"A0005_pythonmode/README.md","ref":"A0005_pythonmode/README.md","articles":[{"title":"使用python模式","level":"1.8.1","depth":2,"path":"A0005_pythonmode/A01_use.md","ref":"A0005_pythonmode/A01_use.md","articles":[]},{"title":"内置python函数介绍","level":"1.8.2","depth":2,"path":"A0005_pythonmode/A02_buildin.md","ref":"A0005_pythonmode/A02_buildin.md","articles":[]},{"title":"自定义python","level":"1.8.3","depth":2,"path":"A0005_pythonmode/A03_selfdefine.md","ref":"A0005_pythonmode/A03_selfdefine.md","articles":[]},{"title":"数据驱动DDT","level":"1.8.4","depth":2,"path":"A0005_pythonmode/A04_ddt.md","ref":"A0005_pythonmode/A04_ddt.md","articles":[]}]},"previous":{"title":"内置关键字介绍","level":"1.7.2","depth":2,"path":"A0004_keyword/A02_buildin.md","ref":"A0004_keyword/A02_buildin.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","theme-comscore","splitter"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"splitter":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"sosotest","gitbook":"*","theme-default":{"showLevel":true}},"file":{"path":"A0004_keyword/A03_selfdefine.md","mtime":"2019-06-17T09:17:09.031Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-06-19T14:58:27.203Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

